#define  _CRT_SECURE_NO_WARNINGS 1

#include "Queue.h"
#include "Heap.h"

void TestQueue()
{
	Queue Qu;
	QueueInit(&Qu);
	printf("QueueSize: %d\n", QueueSize(&Qu));

	QueuePush(&Qu, 1);
	QueuePush(&Qu, 2);
	QueuePush(&Qu, 3);
	printf("QueueBack: %d\n", QueueBack(&Qu));

	QueuePush(&Qu, 4);
	QueuePush(&Qu, 5);
	QueuePush(&Qu, 6);
	printf("QueueBack: %d\n", QueueBack(&Qu));
	printf("QueueSize: %d\n", QueueSize(&Qu));

	while (!QueueEmpty(&Qu))
	{
		printf("%d ", QueueFront(&Qu));
		QueuePop(&Qu);
	}
	printf("\n");
	printf("QueueSize: %d\n", QueueSize(&Qu));

	QueueDestory(&Qu);
}

void TestTopK()
{
	TopK();
}

void TestHeapSort()
{
	int n = 50;
	int* arr = (int*)malloc(n * sizeof(int));
	if (arr == NULL)
	{
		perror("malloc fail");
		exit(-1);
	}
	for (int i = 0; i < n; ++i)
	{
		arr[i] = rand() % 100;
	}

	for (int i = 0; i < n; ++i)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	HeapSort(arr, n);

	for (int i = 0; i < n; ++i)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");

}

void TestHeap()
{
	Heap Hp;
	HeapInit(&Hp);

	HeapPush(&Hp, 1);
	HeapPush(&Hp, 2);
	HeapPush(&Hp, 3);
	HeapPush(&Hp, 4);
	HeapPush(&Hp, 5);
	HeapPush(&Hp, 6);
	HeapPush(&Hp, 7);
	HeapPush(&Hp, 8);
	HeapPush(&Hp, 9);
	HeapPush(&Hp, 10);
	HeapPush(&Hp, 11);
	/*HeapShow(&Hp);

	HeapPop(&Hp);
	HeapPop(&Hp);
	HeapPop(&Hp);
	HeapShow(&Hp);*/

	printf("HeapSize: %d\n", HeapSize(&Hp));
	while (!HeapEmpty(&Hp))
	{
		printf("%d ", HeapTop(&Hp));
		HeapPop(&Hp);
	}
	printf("\n");
	printf("HeapSize: %d\n", HeapSize(&Hp));


	HeapDestory(&Hp);
}

int main()
{
	srand((unsigned int)time(NULL));
	//TestQueue();
	//TestTopK();
	//TestHeapSort();
	TestHeap();

	return 0;
}